package post

import (
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/suite"
	"notabug.org/ropemann/imabon/src/common"
)

type PostTestSuite struct {
	suite.Suite
	author   string
	body     string
	image    string
	threadId string
	board    string
	postId   string
}

func (s *PostTestSuite) SetupSuite() {
	common.LoadConfig("../../../.env")

	s.author = "test_author"
	s.body = "test_body"
	s.image = "test_image"
	s.threadId = "625b8273c84324aea98ce004"
	s.board = "ani"
}

func (s *PostTestSuite) TestNewPost() {
	post := NewPost(s.author, s.body, s.image)
	assert.Equal(s.T(), s.author, post.AuthorName)
	assert.Equal(s.T(), s.body, post.Body)
	assert.Equal(s.T(), s.image, post.Image)
	assert.NotNil(s.T(), post.AuthorId)
}

func (s *PostTestSuite) TestCreatePost() {
	post := NewPost(s.author, s.body, s.image)
	res, err := CreatePost(s.board, s.threadId, post)

	b, _ := post.ID.MarshalJSON()
	s.postId = strings.ReplaceAll(string(b), "\"", "")

	assert.Nil(s.T(), err)
	assert.NotNil(s.T(), res)
}

func (s *PostTestSuite) TestDeletePost() {
	res, err := DeletePost(s.board, s.threadId, s.postId)
	assert.Nil(s.T(), err)
	assert.Greater(s.T(), int(res), 0)
}

func TestPostTestSuite(t *testing.T) {
	suite.Run(t, new(PostTestSuite))
}
